package mth.weightconsolidation;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class WeightConsolidation {

	public static String PATH_TO_WEIGHT_FILES="/home/freefreekk/Entwicklung/step4/method/dataset/weights"; 
	//statistic should contain:
	//qValue, kValue, pairCount, distMeasure, ... hmm ... why not appending to "normal" statistics?
	public static String[] addStringToArray(String[] array, String val) {
		if (array==null || array.length==0) 
			array = new String[0];
		String[] helper = new String[array.length+1];
		for (int a=0; a<array.length; a++) {
			helper[a]=array[a];
		}
		helper[array.length] = val;
		array = new String[helper.length];
		array=helper;
		return array;
	}
	
	private void createStatistics() {
		// TODO Auto-generated method stub
		
	}
	
	private void readWeightFiles() {
		File weightFolder = new File(PATH_TO_WEIGHT_FILES);
		String[] files = weightFolder.list();
		
		BufferedReader lineRider;
		try {
			lineRider = new BufferedReader(new FileReader(PATH_TO_WEIGHT_FILES));
			String element=lineRider.readLine();
			while (element!=null) {
				files=addStringToArray(files, element);
				element = lineRider.readLine();
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * @param args
	 * method - Basu or me are allowed values
	 * dataset - iris, synth, whitewine or yeast are allowed values
	 */
	public static void main(String[] args) {
		String method = "Basu"; //for debugging issues
		String dataset ="iris";
		
		if (args!=null && args.length!=0) {
			for (int a=0; a<args.length; a++) {
				if (args[a].equals("-m")) {
					method = args[++a];
				} else if (args[a].equals("-d")) {
					dataset = args[++a];
				}
			}
		} else {
			System.out.println("Fehlende Parameter.");
//			return;
		}
		if (!method.equals("") && !dataset.equals("")) {
			PATH_TO_WEIGHT_FILES = PATH_TO_WEIGHT_FILES.replaceAll("method", method);
			PATH_TO_WEIGHT_FILES = PATH_TO_WEIGHT_FILES.replaceAll("dataset", dataset);
		}
		
		WeightConsolidation wc = new WeightConsolidation();
		wc.readWeightFiles();
		wc.createStatistics();
	}
}
